package cn.lingyangwl.agile.auth.oauth2.model;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * OAuth2.0 访问令牌的信息
 *
 * @author shenguangyang
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class OAuth2TokenResp implements Serializable {

    @ApiModelProperty(value = "访问令牌")
    private String accessToken;

    @ApiModelProperty(value = "刷新令牌")
    private String refreshToken;

    @ApiModelProperty(value = "用户登录id")
    private String loginId;

    @ApiModelProperty(value = "登录租户id")
    private String loginTenantId;

    @ApiModelProperty(value = "客户端id")
    private String clientId;

    @ApiModelProperty(value = "授权类型")
    private String grantType;

    @ApiModelProperty(value = "第三方平台id")
    private String openId;

    @ApiModelProperty(value = "用户编号")
    private Long userId;

    @ApiModelProperty(value = "访问令牌类型")
    private String tokenType;

    @ApiModelProperty(value = "授权范围")
    private List<String> scopes;

    @ApiModelProperty(value = "过期时间")
    private Long expiresAt;

    @ApiModelProperty(value = "颁发时间")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private LocalDateTime issuedAt;

    @ApiModelProperty(value = "附加参数")
    @Builder.Default
    private Map<String, Object> additionalParameters = new HashMap<>();

}
